package net.maku.controller;

import java.util.List;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.maku.bean.query.WebPayRecordQuery;
import net.maku.bean.vo.PayOrderVo;
import net.maku.bean.vo.TestResultVO;
import net.maku.bean.vo.WebPayConfigVO;
import net.maku.service.impl.BizTradeServiceImpl;
import net.maku.utils.Result;

@Slf4j
@RestController
@Tag(name="业务交易处理")
@AllArgsConstructor
public class BizTradeController {


    @RequestMapping("/getpayconfig")
    @Operation(summary = "获取支付配置")
    public Result<List<WebPayConfigVO>> getPayConfig(){
    	return Result.ok(bizTradeServiceImpl.getPayConfig());
    }

    @RequestMapping(value = "/uploadphoto", headers = "content-type=multipart/form-data")
    @Operation( summary = "打印文件上传" )
	public Result<TestResultVO>  fileUpload( HttpServletRequest  req, 
			@RequestPart("file") MultipartFile upfile ) {
    	log.info("==============fileUpload=========================");
    	log.info( upfile.getSize()+"" );
    	log.info( upfile.getOriginalFilename() );
		return Result.ok(bizTradeServiceImpl.getTestResult(upfile));
	}
    
    @RequestMapping("/payamount")
    @Operation(summary = "用户充值")
    public Result<PayOrderVo> payamount(@ParameterObject @Valid WebPayRecordQuery query){
    	log.info( "payamount: " +  query.toString() );
    	return Result.ok( bizTradeServiceImpl.callWxPay( query ) );
    }

    @Autowired
    BizTradeServiceImpl bizTradeServiceImpl;
}








